import type { PageResponse } from '@/utils/request'
import request from '@/utils/request'
import type { Dept, Student, StudentEducationInfo, StudentFamilyInfo, StudentScoreInfo } from '@/types/user'

export function getStudent(studentIdCard: string) {
  return request<Student>({
    url: '/system/infor/getInfo',
    method: 'get',
    params: { studentIdCard },
  })
}

export function updateStudent(data: Partial<Student> & { studentIdCard: string }) {
  return request({
    url: '/system/infor/edit',
    method: 'post',
    data,
  })
}

export function getStudentScore(idCard: string) {
  return request<StudentScoreInfo>({
    url: '/system/score/getInfo',
    method: 'post',
    data: { idCard },
  })
}

export function updateStudentScore(data: StudentScoreInfo) {
  return request({
    url: '/system/score/edit',
    method: 'post',
    data,
  })
}

export function getSchoolDictInfo(parent: number, signal?: AbortSignal) {
  return request<Dept[]>({
    url: '/system/dept/newList',
    method: 'get',
    params: {
      parentId: parent >= 0 ? parent : 100,
    },
    signal,
  })
}

export function getStudentFamilyInfo(studentId: string) {
  return request<StudentFamilyInfo, PageResponse<StudentFamilyInfo>>({
    url: '/system/member/list',
    method: 'get',
    params: {
      studentId,
    },
  })
}

export function updateStudentFamilyInfo(data: Partial<StudentFamilyInfo> & { id: number }) {
  return request({
    url: '/system/member/edit',
    method: 'post',
    data,
  })
}

export function addStudentFamilyInfo(data: StudentFamilyInfo) {
  return request({
    url: '/system/member/add',
    method: 'post',
    data,
  })
}

export function deleteStudentFamilyInfo(ids: string) {
  return request({
    url: `/system/member/${ids}`,
    method: 'delete',
  })
}

export function getStudentEducationInfo(studentId: string) {
  return request<StudentEducationInfo, PageResponse<StudentEducationInfo>>({
    url: '/system/experience/list',
    method: 'get',
    params: {
      studentId,
    },
  })
}

export function updateStudentEducationInfo(data: Partial<StudentEducationInfo> & { id: number }) {
  return request({
    url: '/system/experience/edit',
    method: 'post',
    data,
  })
}

export function addStudentEducationInfo(data: StudentEducationInfo) {
  return request({
    url: '/system/experience/add',
    method: 'post',
    data,
  })
}

export function deleteStudentEducationInfo(ids: string) {
  return request({
    url: `/system/experience/${ids}`,
    method: 'delete',
  })
}

